WWL.radiobutton = function ( name )
{
	var btn = new WWL ( "radiobutton", name );

	btn.items = [];
	btn._instances = [];

	btn.selected = -1;

	btn.to_string = function ()
	{
		var s = '';
		var mode = null;
		var t, l = this.items.length;
		var _obj = this;

		s = '<div class="wwl_' + this.type + '"><div id="' + this.id + '" ';

		if ( this.tooltip ) s += ' title="' + this.tooltip + '"';

		s += this.mk_events ();

		if ( this._is_disabled )
			mode = "disabled";

                s += ' class="' + WWL.mk_class_str ( this, mode ) + '">';

		this._instances = [];

		for ( t = 0; t < l; t ++ )
		{
			var i = this.items [ t ];

			var name = this.name + ":tbtn:" + t;

			s += '<div id="' + name + '">'; // </div>';

			var item = new WWL.togglebutton ( this.name + ":tbtn:" + t );
			item.label = i.get ( "label", "" );
			item.class_name = i.get ( "class_name", "" );
			item.selected = i.get ( "selected", false );
			item._dest_id = name;

			this._set_before_click ( item, t );
	
			var onclick = i.get ( "onclick" );
			if ( onclick ) item.set_event ( 'click', onclick );

			s += item.to_string ();
			s += '</div>';

			this._instances.push ( item );
		}

                s += '</div></div>';

		return s;
	};

	btn._set_before_click = function ( item, pos )
	{
		var _obj = this;
		item.set_event ( 'before-click', function () { _obj._deselect ( pos ); } );
	}

	btn._deselect = function ( pos )
	{
		var t, l = this._instances.length;
		
		for ( t = 0; t < l; t ++ ) 
		{
			this._instances [ t ].select ( false );
		}

		var last_pos = this.selected;
		this.selected = pos;

		if ( pos != last_pos )
			this.send_event ( "change" );
	};

	btn.select = function ( pos )
	{
		this._instances [ pos ].send_event ( "click" );
	};

	/*btn._int_events [ 'over' ]     = function ( widget, div ) { WWL.button._set_class ( widget, div, "hover" + ( btn._is_selected ? "_selected" : "" ) ); };
	btn._int_events [ 'btn_down' ] = function ( widget, div ) { WWL.button._set_class ( widget, div, "click" + ( btn._is_selected ? "_selected" : "" ) ); };
	btn._int_events [ 'btn_up' ]   = function ( widget, div ) { WWL.button._set_class ( widget, div, "hover" + ( btn._is_selected ? "_selected" : "") ); }; 
	btn._int_events [ 'click' ]    = function ( widget, div ) { btn.select ( ! btn._is_selected ); };
	btn._int_events [ 'out' ]      = function ( widget, div ) { WWL.button._set_class ( widget, div, ( btn._is_selected ? "selected" : "" ) ); };
	*/

	return btn;
};
